package edu.gatech.spacetraderteam3.model;

import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import edu.gatech.spacetraderteam3.debug.Debug;
import edu.gatech.spacetraderteam3.view.Assets;


/**
 * Galaxy that contains solar systems
 * @author TBW
 * @version 1.0
 */
public class SpaceGalaxy {
	
    /**
     * The list of solar systems in the galaxy
     */
	private final List<SpaceSolarSystem> systems;
    
	/**
	 * The galaxy's image
	 */
    private final Assets.MiscImage imageAsset = Assets.MiscImage.GALAXY;

    /**
     * Constructor that makes a new ArrayList containing all the prefab Solar systems
     */
    public SpaceGalaxy() {
        systems = new ArrayList<SpaceSolarSystem>();
        for (SSPrefab prefab : SSPrefab.values()) {
            systems.add(new SpaceSolarSystem(prefab));
        }
    }

    /**
     * Gets the solar systems in the Galaxy
     * @return Solar System
     */
    public List<SpaceSolarSystem> getSystems() {
        return systems;
    }
    
    public Set<SpaceSolarSystem> getRandSystems(int num){
    	Set<SpaceSolarSystem> set = new HashSet<SpaceSolarSystem>();
    	while(set.size() < num){
    		set.add(systems.get((int)(Math.random() * systems.size())));
    	}
    	return set;
    }

    /**
     * Gets a specific solar system from an index
     * @param index Index of the solar system to get
     * @return The solar system
     */
    public SpaceSolarSystem getSystemFromIndex(int index) {
        return systems.get(index);
    }

    /**
     * Gets the Galaxy image
     * @return The image
     */
    public BufferedImage getImage() {
        return imageAsset.image();
    }

    /**
     * Randomizes the states within the Galaxy
     */
    public void randomizeState() {
        for (SpaceSolarSystem s : systems) {
            s.randomState();
            Debug.write(s.getName() + " state changed to: " + s.getState(), Debug.VERBOSE);
        }
    }
    
    /**
     * Constructs a string composed of information about the solar systems within the galaxy
     * @return The string
     */
    public String toString() {
    	return "Galaxy object: " + systems.toString();
    }
}
